package cn.enaium.message.specific;

import cn.enaium.message.config.JdbcConfig;
import cn.enaium.message.entity.Muser;
import cn.enaium.message.repository.MuserRepository;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.ibatis.session.SqlSession;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Login {
    //登录
    @GetMapping(value = "/login")
    public String login(String email,String password) {
        JdbcConfig jdbcConfig = new JdbcConfig();
        SqlSession sqlSession= jdbcConfig.getSqlSession();
        //获取用户密码接口的代理对象
        MuserRepository muserRepository=sqlSession.getMapper(cn.enaium.message.repository.MuserRepository.class);
        //查询是否有符合的用户
        String pas = DigestUtils.md5Hex(DigestUtils.md5Hex(password));
        Muser muser=muserRepository.findByEPMuser(email,pas);
//        System.out.println(muser.getId());
//        System.out.println(muser.getEmail());
        //关闭Sql链接
        jdbcConfig.sqlSessionClose();
        sqlSession.close();
        //返回用户
        if (muser.getUid() == null) {
            return "";
        }else {
            return String.valueOf(muser.getUid());
        }
    }
}
